#!/bin/bash

# Ruoyi-ai Application Status Script

APP_NAME="ruoyi-admin"
APP_HOME=$(cd "$(dirname "$0")" && pwd)
PID_FILE="$APP_HOME/app.pid"

echo "Checking status of $APP_NAME..."

# 检查PID文件是否存在
if [ ! -f "$PID_FILE" ]; then
  echo "Application is not running (PID file not found)."
  exit 1
fi

# 读取PID
PID=$(cat "$PID_FILE")

# 检查进程是否存在
if ps -p $PID > /dev/null; then
  echo "$APP_NAME is running. PID: $PID"
  
  # 显示进程详细信息
  ps -p $PID -f
  
  # 显示应用启动时间
  echo ""
  echo "Start time:"
  ps -p $PID -o lstart=
else
  echo "Application is not running (process with PID $PID not found)."
  echo "Removing stale PID file..."
  rm -f "$PID_FILE"
  exit 1
fi